package com.wen.service.impl;

import com.wen.bean.UserInfoBean;
import com.wen.dao.UserInfoBeanMapper;
import com.wen.service.IUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Scanner;

@Service
public class UserServiceImpl implements IUserService {
    // 依赖注入
    @Resource
    private UserInfoBeanMapper userInfoBeanMapper;


    public UserInfoBean queryUserInfoById(Integer userid) {

        return userInfoBeanMapper.queryUserInfoById(userid);
    }


    /**
     * 物理删除
     *
     * @param userid 用户id
     * @return 数据值
     */
    @Override
    public int logicDeleteUserInfoById(Integer userid) {

        return userInfoBeanMapper.logicDeleteUserInfoById(userid);
    }

    /**
     * 物理删除
     *
     * @param userid 用户id
     * @return 数据值
     */
    @Override
    public int deleteUserInfoById(Integer userid) {
        return userInfoBeanMapper.deleteByPrimaryKey(userid);
    }

    /**
     * 根据参数查询用户信息
     *
     * @param userInfoBean 参数实体类
     * @return 查询结果集
     */
    @Override
    public List<UserInfoBean> selectUserinfoByParams(UserInfoBean userInfoBean) {
        return userInfoBeanMapper.selectUserinfoByParams(userInfoBean);
    }

    /**
     * 通过Id查询用户信息
     *
     * @param userid id值
     * @return 结果集
     */
    @Override
    public List<UserInfoBean> selectByPrimaryKey(Integer userid) {

        return userInfoBeanMapper.selectByPrimaryKey(userid);
    }

    @Override
    public boolean doLogin(UserInfoBean userInfoBean) {
        // 调用到层进行登录验证业务逻辑处理
        UserInfoBean userInfoBean1 = userInfoBeanMapper.doLogin(userInfoBean);
        System.out.println("mybatis查询结果：" + userInfoBean1);
        return userInfoBean != null;
    }

    /**
     * 用户信息新增和修改
     *
     * @param userInfoBean 参数实体类
     * @return 操作结果
     */
    @Override
    public int addAndUpdateUserInfo(UserInfoBean userInfoBean) {
        //默认返回值
        int i = 0;
        if (userInfoBean.getUserid() != null) {
            //调用dao层进行数据处理
            i = userInfoBeanMapper.updateByPrimaryKeySelective(userInfoBean);
        } else {
            i = userInfoBeanMapper.insertSelective(userInfoBean);
        }
        return i;
    }

    @Override
    public List<UserInfoBean> userQueryAll() {
        List<UserInfoBean> lst = userInfoBeanMapper.userQueryAll();
        return lst;
    }

    public void setUserInfoBeanMapper(UserInfoBeanMapper userInfoBeanMapper) {
        this.userInfoBeanMapper = userInfoBeanMapper;
    }
}
